Public Class ExchangeRateViewer
    Public CurrencyPairs As Dictionary(Of CurrencyPair.ECurrencyPairSymbol, CurrencyPair)
    Public Sub LoadCurrencyPairs()
        Dim SelectedCurrencyPairAux As String = SelectedCurrencyPair
        Me.CmbCurrencyPairSelector.Items.Clear()
        If CurrencyPairs Is Nothing Then Exit Sub
        CmbCurrencyPairSelector.BeginUpdate()
        For Each CPPair As KeyValuePair(Of CurrencyPair.ECurrencyPairSymbol, CurrencyPair) In CurrencyPairs
            CmbCurrencyPairSelector.Items.Add(CPPair.Key.ToString)
        Next
        CmbCurrencyPairSelector.EndUpdate()
        If SelectedCurrencyPairAux = "" Then SelectedCurrencyPairAux = "EURUSD" ' un default bueno
        SelectedCurrencyPair = SelectedCurrencyPairAux 'restauro el que estaba seleccionado
    End Sub


    Public Sub LoadSelectedCurrencyPairExchangeRate()
        Dim SelectedCurrencyPairObj As CurrencyPair = CurrencyPairs(CurrencyPair.GetCurrencyPairSymbolFromCurrencyPairString(SelectedCurrencyPair))
        If SelectedCurrencyPairObj.HasExchangeRate Then
            Me.LblExchangeRate.Text = SelectedCurrencyPairObj.ExchangeRate.ToString & " (From " & SelectedCurrencyPairObj.LastExchangeRateProvider.ToString & " : " & SelectedCurrencyPairObj.LastUpdateTime & ")"
        Else
            Me.LblExchangeRate.Text = "Not avaliable"
        End If
    End Sub
    Public mSelectedCurrencyPair As String
    Public Property SelectedCurrencyPair() As String
        Get
            If Me.CmbCurrencyPairSelector.SelectedItem IsNot Nothing Then
                Dim SelectedItem As String = Me.CmbCurrencyPairSelector.SelectedItem.ToString
                If CurrencyPair.IsValidCurrencyPairString(SelectedItem) Then
                    mSelectedCurrencyPair = SelectedItem
                Else
                    mSelectedCurrencyPair = ""
                End If
            Else
                mSelectedCurrencyPair = ""
            End If
            Return mSelectedCurrencyPair
        End Get
        Set(ByVal value As String)
            mSelectedCurrencyPair = value
            If CurrencyPair.IsValidCurrencyPairString(value) AndAlso Me.CmbCurrencyPairSelector.Items.Contains(value) Then
                Me.CmbCurrencyPairSelector.SelectedItem = value
            End If
        End Set
    End Property
    Private Sub CmbCurrencyPairSelector_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbCurrencyPairSelector.SelectedIndexChanged
        LoadSelectedCurrencyPairExchangeRate()
    End Sub
End Class
